﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Buffalo.Lib.UI;
using Buffalo.SMECommon.DAL;
using Buffalo.Administration.DAL;
using Buffalo.Lib.Common;
using Buffalo.Administration.DAL.Models;

namespace Buffalo.Web.Areas.SMECommon
{
    public class GeneralVar
    {
        public static string gLoggedUserName
        {
            set {
                LoginInfoDAL  loginInfoDAL  = new LoginInfoDAL ();
                LoginInfo loginInfo = loginInfoDAL.GetLoginInfo(HttpContext.Current.Session.SessionID);
                if (loginInfo == null)
                {
                    loginInfo = new LoginInfo();
                    loginInfo.IDSession = HttpContext.Current.Session.SessionID;
                }
                loginInfo.UserName = value;
                loginInfoDAL.SaveLoginInfo(loginInfo);
            }
            get {
                LoginInfoDAL loginInfoDAL = new LoginInfoDAL();
                LoginInfo loginInfo = loginInfoDAL.GetLoginInfo(HttpContext.Current.Session.SessionID);
                return loginInfo != null ? loginInfo.UserName : string.Empty; 
            }
        }
        public static string gLoggedRoleName
        {
            set
            {
                LoginInfoDAL loginInfoDAL = new LoginInfoDAL();
                LoginInfo loginInfo = loginInfoDAL.GetLoginInfo(HttpContext.Current.Session.SessionID);
                if (loginInfo == null)
                {
                    loginInfo = new LoginInfo();
                    loginInfo.IDSession = HttpContext.Current.Session.SessionID;
                }
                loginInfo.RoleName = value;
                loginInfoDAL.SaveLoginInfo(loginInfo);
            }
            get
            {
                LoginInfoDAL loginInfoDAL = new LoginInfoDAL();
                LoginInfo loginInfo = loginInfoDAL.GetLoginInfo(HttpContext.Current.Session.SessionID);
                return loginInfo != null ? loginInfo.RoleName : string.Empty;
            }

        }
        public static int gLoggedRemember
        {
            set
            {
                LoginInfoDAL loginInfoDAL = new LoginInfoDAL();
                LoginInfo loginInfo = loginInfoDAL.GetLoginInfo(HttpContext.Current.Session.SessionID);
                if (loginInfo == null)
                {
                    loginInfo = new LoginInfo();
                    loginInfo.IDSession = HttpContext.Current.Session.SessionID;
                }
                loginInfo.Remember = value;
                loginInfoDAL.SaveLoginInfo(loginInfo);
            }
            get
            {
                LoginInfoDAL loginInfoDAL = new LoginInfoDAL();
                LoginInfo loginInfo = loginInfoDAL.GetLoginInfo(HttpContext.Current.Session.SessionID);
                return loginInfo != null ? Util.ToSafeInt(loginInfo.Remember) : 0;
            }
        }
        public static string gLoggedPassword
        {
            set
            {
                LoginInfoDAL loginInfoDAL = new LoginInfoDAL();
                LoginInfo loginInfo = loginInfoDAL.GetLoginInfo(HttpContext.Current.Session.SessionID);
                if (loginInfo == null)
                {
                    loginInfo = new LoginInfo();
                    loginInfo.IDSession = HttpContext.Current.Session.SessionID;
                }
                loginInfo.Password = value;
                loginInfoDAL.SaveLoginInfo(loginInfo);
            }
            get
            {
                LoginInfoDAL loginInfoDAL = new LoginInfoDAL();
                LoginInfo loginInfo = loginInfoDAL.GetLoginInfo(HttpContext.Current.Session.SessionID);
                return loginInfo != null ? loginInfo.Password : string.Empty;
            }
        }

        public static ExtNetLocalizationHelper gLanguageHelper
        {
            get
            {
                return ExtNetLocalizationHelper.Instance;
            }
        }
    }
}
